//const postData = require('../../data/post-data.js');

// pages/posts/posts.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    posts: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    app.getAccessToken().then(function(){
      var _token = wx.getStorageSync("token");
      wx.request({
        url: 'http://www.hp.com/index.php/api/Banner/article?token=' + _token, //仅为示例，并非真实的接口地址
        success (res) {
         // console.info(res.data);
          if (res.data.code == 1) {
            //console.info(res.data.data);
            that.setData({
              posts : res.data.data,
              array : res.data.swiper,
            })
          } else {
            console.info(res);
          }
        }
      })
    });
  },

  onPostTap: function(e) {
    //console.info(e);
    const postId = e.currentTarget.dataset.postId;
    wx.navigateTo({
      url: `post-detail/post-detail?id=${postId}`
    })
  },

  onSwiperTap: function(e) {
    //console.info(e);
    const postId = e.target.dataset.postId;
    wx.navigateTo({
      url: `post-detail/post-detail?id=${postId}`
    })
  }
})